package com.spark.mapstruct;

import com.spark.mapstruct.entity.ExpensesRecords;
import com.spark.mapstruct.vo.PayInfo;
import com.spark.mapstruct.vo.PayInfoMapper;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * https://www.toutiao.com/i6826263580548006403/
 */
@Log
@SpringBootApplication
public class MapstructApplication implements CommandLineRunner {


    @Autowired
    private PayInfoMapper mapper;


    public static void main(String[] args) {
        SpringApplication.run(MapstructApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        convert();
    }

    private void convert() {
        PayInfo payInfo = new PayInfo();
        payInfo.setPayCode("20200513_01471111_120_40_1589359038744");
        //BigDecimal自动转换，
        payInfo.setTotalMoney("39.3");
        payInfo.setServiceId("001");
        payInfo.setServiceName("服务商A");
        payInfo.setRestaurantCode("A001");
        payInfo.setRestaurantName("餐厅A");
        payInfo.setMachineCode("M001");
        payInfo.setExpensesType("1");
        //时间也会按格式进行转换，
        payInfo.setExpensesDate("2020-05-15 12:43:12");

        ExpensesRecords expensesRecords =
                mapper.payInfo2ExpensesRecords(payInfo);

        log.warning(expensesRecords.toString());
    }
}
